package com.virgo.demo.support.controller.admin;

import com.virgo.common.entity.IResponse;
import com.virgo.demo.support.domain.vo.AreaVo;
import com.virgo.demo.support.service.AreaService;
import com.virgo.web.utils.IRequestUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/manage168/area")
@RequiredArgsConstructor
public class AreaController {

	private final AreaService areaService;

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public IResponse<List<AreaVo>> listAction(HttpServletRequest request) {
		long parentId = IRequestUtils.getLong(request,"parentId");
		if (parentId < 0L) {
			return IResponse.fail("参数错误");
		}
		return IResponse.ok(areaService.findList(parentId));
	}

	@RequestMapping(value = "/info", method = RequestMethod.POST)
	public IResponse<AreaVo> infoAction(HttpServletRequest request) {
		long id = IRequestUtils.getLong(request,"id");
		if (id < 1L) {
			return IResponse.fail("参数错误");
		}
		return IResponse.ok(areaService.findInfo(id));
	}

}